package com.hice.demo.sbdbra.quartz;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import javax.jms.Topic;

/**
 * activemq定时发送信息
 *
 * @author hyson
 * @create 2017-02-27 16:32
 */
@Component
@EnableScheduling
public class ActiveMQTopicSchedu {

    @Autowired
    private JmsMessagingTemplate jmsTemplate;

    @Autowired
    private Queue queue;

    @Autowired
    private Topic topic;

    @Scheduled(fixedDelay = 3000)//每3s执行1次
    public void send() {
        //send queue.
        this.jmsTemplate.convertAndSend(this.queue, "hi,activeMQ");
        //send topic.
        this.jmsTemplate.convertAndSend(this.topic, "hi,activeMQ(topic)");
    }

}
